package com.hxkj.controller;

import com.hxkj.domain.po.Manuscript;
import com.hxkj.service.ManscriptService;
import com.platform.common.domain.exception.CustomException;
import com.platform.common.domain.result.ResultDataStruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * 模板解析控制层
 * <p>
 * Created by yaosy on 2018年6月19日09:23:15
 */
@RestController
@RequestMapping("/manuscript")
public class ManuscriptController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ManuscriptController.class);

    @Autowired
    private ManscriptService manscriptService;

    /**
     *获取一条静态文件记录（ 首页 或者 频道）
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/get")
    public Callable<ResultDataStruct<Manuscript>> getManuscript(@RequestBody Manuscript manuscript) throws Exception {
        return ()-> {
            ResultDataStruct<Manuscript> resultStruct = new ResultDataStruct<>();
            try{
                resultStruct.setData(manscriptService.getManuscript(manuscript));
                resultStruct.setCode(200);
                resultStruct.setMessage("成功");
            }catch (CustomException e){
                resultStruct.setCode(e.getCode().getCode());
                resultStruct.setMessage(e.getMessage());
            }
            return resultStruct;
        };

    }

    /**
     *保存或修改稿件表
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/saveOrUpdate")
    public void saveOrUpdate(@RequestBody Manuscript manuscript) throws Exception{
        manscriptService.saveOrUpdate(manuscript);
    }


    /**
     *保存或修改稿件表
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/getMaxSeqNum")
    public Callable<Integer> getMaxSeqNum() throws Exception{
        return ()-> manscriptService.getMaxSeqNum();
    }

    /**
     *删除稿件表
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/deleteManuscript")
    public void deleteManuscript(@RequestBody Long manuscriptId) throws Exception{
         manscriptService.deleteManuscript(manuscriptId);
    }



    /**
     * 根据站点、状态、文章id查询出生成的文件
     *
     * @param
     * @throws Exception
     */
    @RequestMapping(value = "/getManuscriptList")
    public Callable<List<Manuscript>> getManuscriptList(@RequestBody Manuscript manuscript) throws Exception{
        return () ->  manscriptService.getManuscriptList(manuscript);
    }




}
